/*
 * Created on Mar 5, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package ModuleBuilder.UI.tree;

import javax.swing.JTree;
import javax.swing.tree.*;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import java.util.*;
import ModuleBuilder.model.*;

/**
 * @author Milton  Soong
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class Util {
	public static DefaultMutableTreeNode findOBNode( DefaultMutableTreeNode root ) {
		return ( findSpecificNodeType(root, GameModel.OB_EDITOR) );
//		DefaultMutableTreeNode obNode = null;
//		Enumeration e = root.children();
//		while (e.hasMoreElements()){
//			DefaultMutableTreeNode currNode = (DefaultMutableTreeNode)e.nextElement();
//			GameModel gameMod = (GameModel)currNode.getUserObject();
//			if ( gameMod.getEditorName().equals(GameModel.OB_EDITOR) ){
//				obNode = currNode;
//				break;
//			}
//		}
//		return ( obNode );
	}
	
	public static DefaultMutableTreeNode findProfileNode( DefaultMutableTreeNode root ) {
		return ( findSpecificNodeType(root, GameModel.UNIT_PROFILE_EDITOR) );		
	}
	
	public static DefaultMutableTreeNode findSpecificNodeType(DefaultMutableTreeNode root, String type) {	
		DefaultMutableTreeNode node = null;
		Enumeration e = root.children();
		while (e.hasMoreElements()){
			DefaultMutableTreeNode currNode = (DefaultMutableTreeNode)e.nextElement();
			GameModel gameMod = (GameModel)currNode.getUserObject();
			if ( gameMod.getEditorName().equals(type) ){
				node = currNode;
				break;
			}
		}
		return ( node );
	}

}
